package com.itsu.vtalk.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author suben
 * @createtime 2020/6/20 20:34
 **/

@Component
public class SpringContextUtil implements ApplicationContextAware {

    private static ApplicationContext ioc = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ioc = applicationContext;
    }

    public static Object getBean(String beanName) {
        return ioc.getBean(beanName);
    }

    public static <T> T getBean(Class<T> beanClass){
        return ioc.getBean(beanClass);
    }
}
